package com.sourcetrip.my.modle;

/**
 * @author: ZhouBert
 * @date: 2020/12/24
 * @description: 映射的红黑树节点
 */
public class RedBlackNode4Map<K, V> extends RedBlackNode<K> {

	public V value;

	/**
	 * 默认红色
	 * 因为在红黑树中，新添加的节点就是红色的。
	 *
	 * @param element
	 * @param parent
	 */
	public RedBlackNode4Map(K element, TreeNode<K> parent) {
		super(element, parent);
	}

	/**
	 * constructor
	 * @param element	红黑树中的元素 key
	 * @param value	红黑树中元素 value
	 * @param parent	节点的父节点
	 */
	public RedBlackNode4Map(K element, V value, TreeNode<K> parent) {
		super(element, parent);
		this.value = value;
	}

	@Override
	public String toString() {
		String parentString = "null";
		if (this.parent != null) {
			parentString = this.parent.element.toString();
		}
		String value=this.value==null?" ":this.value.toString();
		return this.element + "_"+value +
				"_p(" + parentString + ")" + "_(" + ((this.color.equals(RedBlackNode.Color.Red)) ? "红" : "黑") + ")";
	}
}
